home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 001a / mskrmsrc.zip / MSNSED.C < prev    next >
C/C++ Source or Header  |  1991-10-24  |  4KB  |  160 lines

  1. /* File MSNSED.C
  2.  * Ethernet Driver support routines
  3.  *
  4.  * Copyright (C) 1991, University of Waterloo.
  5.  * Copyright (C) 1991, Trustees of Columbia University in the
  6.  *  City of New York.  Permission is granted to any individual or
  7.  *  institution to use, copy, or redistribute this software as long as
  8.  *  it is not sold for profit and this copyright notice is retained.
  9.  *
  10.  * Original version created by Erick Engelke of the University of
  11.  *  Waterloo, Waterloo, Ontario, Canada.
  12.  * Adapted and modified for MS-DOS Kermit by Joe R. Doupnik, 
  13.  *  Utah State University, jrd@cc.usu.edu, jrd@usu.Bitnet.
  14.  *
  15.  * Last edit
  16.  * 6 Sept 1991
  17.  *
  18.  *  The TCP code uses Ethernet constants for protocol numbers and 48 bits
  19.  *  for address.  Also, 0xffffffffffff is assumed to be a broadcast.
  20.  *
  21.  *  If you need to write a new driver, implement it at this level and use
  22.  *  the above mentioned constants as this program's constants, not device
  23.  *  dependant constants.
  24.  *
  25.  *  The packet driver code lies below this.
  26.  *
  27.  *  eth_addr    - Ethernet address of this host.
  28.  *  eth_brdcast    - Ethernet broadcast address.
  29.  */
  30.  
  31. #include "msntcp.h"
  32. #include "msnlib.h"
  33.  
  34. #define ETH_MIN    60              /* Minimum Ethernet packet size */
  35.  
  36. eth_address eth_addr = {0};    /* local ethernet address */
  37. eth_address eth_brdcast;    /* Ethernet broadcast address */
  38. word pktdevclass = 1;        /* Ethernet = 1, SLIP = 6 */
  39.  
  40. /* Ethernet Interface */
  41.  
  42. struct ether {
  43.     byte    dest[6];
  44.     byte    src[6];
  45.     word    type;
  46.     byte    data[ETH_MSS + 60];
  47. };
  48. static struct ether outbuf = {{0},{0},0,{0}};
  49.  
  50. /*
  51.  *  Initialize the Ethernet Interface, and this package.  Enable input on
  52.  *  all packet buffers.
  53.  */
  54. int 
  55. eth_init()
  56. {
  57. /* Init Packet Driver, get Ethernet address, set bdcast address to all 1's */
  58.     memset(&outbuf, 0, sizeof(struct ether));
  59.     if (pkt_eth_init() == 0)
  60.         return (0);                /* 0 is failure */
  61.     memset(eth_brdcast, 0xff, sizeof(eth_address));
  62.     return (1);                    /* success */
  63. }
  64.  
  65. /*
  66.  * eth_FormatPacket places the next packet into the buffer and uses the
  67.  * type field for protocol determination.  Note, I only maintain a single
  68.  * output buffer, and it gets used quickly then released.  The benefits of
  69.  * non-blocking systems are immense.
  70.  */
  71.  
  72.  
  73. byte *
  74. eth_formatpacket(void *eth_dest, word eth_type)
  75. {
  76.     if (eth_dest == NULL) return (NULL);    /* failure */
  77.  
  78.     memset(&outbuf, 0, sizeof(struct ether));
  79.  
  80.     switch (pktdevclass) {
  81.     case PD_ETHER :
  82.         bcopy(eth_dest, outbuf.dest, 6);
  83.         bcopy(eth_addr, outbuf.src, 6);
  84.         outbuf.type = eth_type;
  85.         return(outbuf.data);        /* outbuf is permanent */
  86.     case PD_SLIP :
  87.         return(outbuf.dest);    /* really data because no header */
  88.     }
  89.     return (NULL);                /* default */
  90. }
  91.  
  92. /*
  93.  * eth_send does the actual transmission once we are complete with the
  94.  * buffer.  Do any last minute patches here, like fix the size.
  95.  */
  96. int
  97. eth_send(word len)
  98. {
  99.  
  100.     if ((pktdevclass == PD_ETHER) && ((len += 14) < ETH_MIN))
  101.     len = ETH_MIN;
  102.     return (pkt_send((byte *) &outbuf, len));    /* send to packet driver */
  103. }
  104.  
  105. /*
  106.  * eth_free - free an input buffer once it is no longer needed
  107.  * If pointer to NULL, release all buffers
  108.  */
  109. void 
  110. eth_free(void *buf)
  111. {
  112.     if (buf != NULL)
  113.     pkt_buf_release(buf);        /* free this buffer ptr */
  114.     else
  115.     pkt_buf_wipe();            /* if none then clear all */
  116. }
  117.  
  118. /*
  119.  * eth_arrived - if a new packet has arrived, read it and fill pointer
  120.  * with type of packet
  121.  */
  122.  
  123. byte * 
  124. eth_arrived(word *type_ptr)
  125. {
  126.     struct ether * temp;
  127.  
  128.     if (type_ptr == NULL) return (NULL);
  129.  
  130.     if ((temp = (struct ether *)pkt_received()) != NULL) {
  131.     switch (pktdevclass) {
  132.         case PD_ETHER: *type_ptr = temp->type;    /* value of TYPE */
  133.                return(temp->data);        /* address of data */
  134.         case PD_SLIP: *type_ptr = 0x0008;
  135.               return((byte *)temp);    /* none to skip */
  136.         default: return (NULL);
  137.     }
  138.     }
  139.     return(NULL);
  140. }
  141.  
  142. /*
  143.  * eth_release - release the hardware
  144.  */
  145. void 
  146. eth_release()
  147. {
  148.     pkt_release();
  149. }
  150.  
  151. /*
  152.  * eth_hardware - return pointer to hardware address of a packet
  153.  */
  154. void *
  155. eth_hardware(byte *p)
  156. {
  157.     if (p == NULL) return (NULL);
  158.     return(p - 8);
  159. }
  160.